package com.base.chat.presenter;

import android.app.Activity;

import com.base.chat.view.ChatWindowView;
import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.http.CallBackFroPark;
import com.base.commonlib.http.FileBean;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.http.ResponseT;
import com.base.commonlib.http.utils.CallBackImpl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.disposables.Disposable;

public class ChatWindowPresenter extends BasePresenter<ChatWindowView> {
    public ChatWindowPresenter(ChatWindowView view, Activity activity) {
        super(view, activity);
    }


    /**
     * 发送文本消息
     * @param content
     * @param friendUserId
     */
    public void sendTextMsg(String content,String friendUserId){
        Map<String, String> map = new HashMap<>();
        map.put("text",content);
        map.put("messageToType","USER");
        map.put("toId","1111111");
        map.put("friendUserId",friendUserId);
        Disposable enqueue = RealNetWorkUtil.postContent().method("api-im/message/sendMessage")
                .content(map)
                .build().enqueue(String.class, new CallBackImpl<String>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.showError();
                        mView.returnSendTextMsgError();
                    }

                    @Override
                    public void onNext(String s) {
                        mView.returnSendTextMsgSuccess(s);
                    }
                });
        mCompositeDisposable.add(enqueue);
    }




/*
    public void addLook2(List<String> list,AddLookBean addLookBean){
        Map<String,Object>maps= MapTrunPojo.object2Map(addLookBean);
        mView.showPb_mes("正在上传。。。");
        List<String> paths = new ArrayList<>();
        if (list.toString().contains("mp4")){
            for (String fils : list){
                paths.add(fils);
            }
        }else {
            for (String fils : list){
                paths.add(BitmapUtil.compressImage(fils));
            }
        }

        //压缩完成
        List<FileBean> mFileList = new ArrayList<>();
        FileBean mFileBean = null;
        for (String str : paths){
            mFileBean = new FileBean("files",str);
            mFileList.add(mFileBean);
        }
        Disposable enqueue = RealNetWorkUtil.postPics().method("api-view/publish").filePaths(mFileList)
                .params(maps)
                .build().enqueueForUpFiles(new CallBackFroPark<ResponseT>() {
                    @Override
                    public void onResponse(ResponseT responseT) throws Exception {
                        mView.hidePb_mes();
                        // mHasSaved = true;
                        mView.returnAddLookSuccess(responseT.getMsg());
                       // mView.showMes(responseT.getData().toString());
                    }

                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb_mes();
                        mView.returnAddLookError();
                    }

                    @Override
                    public void onNext(ResponseT responseT) {
                        if (responseT == null){
                            mView.hidePb_mes();
                            mView.returnAddLookSuccess(responseT.getMsg());
                        }
                    }
                });
        mCompositeDisposable.add(enqueue);
    }



    public void addLook3(List<String> list,AddLookBean addLookBean){
        Map<String,Object>maps= MapTrunPojo.object2Map(addLookBean);
        mView.showPb_mes("正在压缩图片。。。");
        List<String> paths = new ArrayList<>();
        for (String fils : list){
            paths.add(fils);
        }
        //压缩完成
        List<FileBean> mFileList = new ArrayList<>();
        FileBean mFileBean = null;
        for (String str : paths){
            mFileBean = new FileBean("files",str);
            mFileList.add(mFileBean);
        }
        Disposable enqueue = RealNetWorkUtil.postFile().method("api-view/publish").filePaths(mFileList)
                .params(maps)
                .build().enqueueForUpFiles(new CallBackFroPark<ResponseT>() {
                    @Override
                    public void onResponse(ResponseT responseT) throws Exception {
                        mView.hidePb_mes();
                        // mHasSaved = true;
                        mView.returnAddLookSuccess(responseT.getMsg());
                    }

                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb_mes();
                        mView.returnAddLookError();
                    }

                    @Override
                    public void onNext(ResponseT responseT) {
                        if (responseT == null){
                            mView.hidePb_mes();
                            mView.returnAddLookSuccess(responseT.getMsg());
                        }
                    }
                });

        mCompositeDisposable.add(enqueue);
    }

*/

}
